﻿using System;
using System.Windows;

namespace CrackNET
{
    public partial class App : Application
    {
        public App()
        {
            AppDomain.CurrentDomain.UnhandledException += this.OnCurrentDomainUnhandledException;
        }

        void OnCurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            bool isServicePack1Installed = typeof(System.Windows.Data.BindingBase).GetProperty("StringFormat") != null;

            if (!isServicePack1Installed)
            {
                MessageBox.Show(
                    "Crack.NET requires the .NET 3.5 Framework with Service Pack 1 to be installed.",
                    "Cannot Run",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);
            }
            else
            {
                string msg = e.ExceptionObject == null ? "(no error message is available)" : e.ExceptionObject.ToString();
                Clipboard.SetText(msg);

                MessageBox.Show(
                    "Crack.NET threw an unhandled exception.  The following exception details have been copied to the Windows clipboard.  Please report this issue here: http://www.codeplex.com/cracknetproject \n\n" + msg,
                    "Unexpected Error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }

            System.Diagnostics.Process.GetCurrentProcess().Kill();
        }
    }
}